﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="analyze_main" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>KYOWON CREATIVE 지문 분석 System (V2.0)</title>
	<script type="text/javascript" src="/js/jquery-1.6.1.min.js"></script>
	<script type="text/javascript" src="/js/jquery.selectbox-0.6.1.js"></script>
	<script type="text/javascript" src="/js/ui.js"></script>
	<link rel="stylesheet" type="text/css" href="/css/common.css" />
	
    <script type="text/javascript">
    
    var selectedData = eval(<%=sData%>);
    
    $(document).ready(function(){
       // 파일박스관리 : 첨부파일
		$('.atch_file').change(function(){
			var upfile = $(this).val();
			$('.filenameview').val( upfile );
			// 첨부파일 가공
			val = upfile.split("\\");
			file_name = val[val.length-1]; //마지막 화일명
			ext_name  = file_name.substring(file_name.indexOf("."), file_name.length);//확장자빼오기
			ext = ext_name.toLowerCase();
			
			// 확장자 검사
			if(ext.indexOf('txt , docx') < 0){
				
			} else {
				alert('사용가능한 파일이 아닙니다.');
				$('.filenameview').val('');
				$(this).val();
				return false;
			}
		});
		
		setSelect(0, "0");
	});
    
    function form_submit()
    {
        var input_form = document.input_form;
        
        if (input_form.text.value == "")
        {
            alert("분석 대상 지문을 입력해주세요.");
            input_form.text.focus();
            return;
        }
        
        loading();
        
        input_form.uploadfile.value = "";
        input_form.submit();
    }
    
    function upload()
    {
        var input_form = document.input_form;
        
        if (input_form.uploadfile.value == "")
        {
            alert("분석 대상 지문 파일을 선택해주세요.");
            input_form.uploadfile.focus();
            return;
        }
        
        loading();
        
        input_form.text.value = "";
        input_form.submit();
    }
    
    function text_clear()
    {
        var input_form = document.input_form;
        input_form.text.value = ""; 
        input_form.text.focus();   
    }
    
    function excel_download()
    {
        var excel_form = document.excel_form;
        var addTag = '<div class="lside"><h3>레벨 별 단어 상세보기</h3></div>';
        var text = document.getElementById("word_excel").innerHTML + addTag + document.getElementById("word_excel2").innerHTML;
        
        text = text.replace($("#fe").html(), "").replace($("#al").html(), "").replace($("#excel_replace").html(), "");
        text = text.replace(/<table/g, "<table border=1");
        
        excel_form.word_excel.value = text;
        excel_form.submit();
    }
    
    function sort(){
        $("#lv, #fe, #al").hide();
        $("#" + $("#sortSelect").val()).show();
    }
    
    function setSelect(seq, topId){
	    var param = {action:"getLevel", topId : topId};
	    var select = $("div .select").eq(seq);
	    
		$(select).html("<option value=''>선택하세요</option>");
		$("div .select").eq(2).html("<option value=''>선택하세요</option>").refresh_selectbox();
		
	    $.ajax({
		    type     : "post",
		    dataType : "json",
		    url      : "/analyze_new/admin/level/levelAction.aspx",
		    data     : param,
		    cache    : false,
		    async    : false,
		    success  : function(data){
		        var inSelected = false;
                if(data != null){
                    for(var i=0; i<data.length; i++){
                        var sel = '';
                        if(selectedData){
                            if(selectedData[seq+""] == data[i].LevelId){
                                sel = ' selected="selected" ';
                                inSelected = true;
                            }
                        }
                        var option = "<option value='"+data[i].LevelId+"'"+sel+">"+ data[i].LevelName+"</option>";
                        $(select).append(option);
                    }
                }
                $(select).refresh_selectbox().change(function(){
                    if(seq < 2 && $(this).val() != ""){
                        var t = $(this).val();
                        setSelect(seq+1, t, '');
                    }
                });
                
                if(inSelected){
                    $(select).change();
                }
		    },
		    error    : function(err){
			    alert(err);
		    }
	    });
	}
	
	function loading(){
	    // 스크롤 포함한 총 높이, 총 넓이
		var winHT = $(document).height();
		var winWT = $(document).width();
		
		// 스크롤 제외한 높이, 넓이
		var winH = $(window).height();
		var winW = $(window).width();
		
		// 현재 스크롤 위치 값
		var scrollH = $(document).scrollTop();
		var scrollW = $(document).scrollLeft();
		
		if(scrollH > 0){
			winH = scrollH + (winH/2);
		}else{
			winH = winH/2;
		}
		
		if(scrollW > 0){
			winW += scrollW;
		}
		$("body").append('<div class="loadImgClss" style="position:absolute; z-index:50;"><img src="/images/loadImg.gif" /></div>');
		$(".loadImgClss").css('top',  winH);
		$(".loadImgClss").css('left', winW/2);
	}
</script>
</head>
<body class="login">
<form id="excel_form" name="excel_form" method="post" action="/analyze_new/excel_new.aspx">
    <input type="hidden" name="word_excel" />
</form>

<form id="input_form" name="input_form" method="post" action="main.aspx" onsubmit="return false" enctype="multipart/form-data">
<div class="wrap">
	<!-- header -->
		<div id="header">
		    <span style="position:absolute; left:610px; padding-top: 18px;"><a href="/analyze_new/admin/loginAction.aspx?mode=2&qs=<%=qs%>">&nbsp;&nbsp;</a></span>
			<h1>KYOWON CREATIVE 지문 분석 System (V2.0)</h1>
		</div>
		<!-- //header -->
        
        <!-- contents -->
		<div id="contents">
			<!-- search -->
			<div class="board_write">
					<table>
					<caption>검색</caption>
					<colgroup>
						<col width="136" />
						<col width="*" />
					</colgroup>
					<tbody>
					<tr>
						<th scope="row"><em>레벨 선택</em></th>
						<td>
							<div class="article">
								<select class="select" name="sel_Level1" style="width:100px;">
									<option>선택하세요</option>
								</select>
								<select class="select" name="sel_Level2" style="width:100px;">
									<option>선택하세요</option>
								</select>
								<select class="select" name="LevelId" style="width:100px;">
									<option>선택하세요</option>
								</select>
							</div>
						</td>
					</tr>
					<tr>
						<th scope="row"><em>파일 업로드</em></th>
						<td>
						    <div class="article">
								<div class="file">
								    <input type="text" class="adm_input filenameview" name="textfield" style="width:384px;" />
								    <span class="fileInputForm">
									    <input type="file" name="uploadfile" class="atch_file" />
								    </span>
								    <p>* txt, docx 파일만 지원</p>		
							    </div>
							    <a href="javascript:upload();" class="btn_orange24"><span>업로드</span></a>
						    </div>
						    <!--//fileArea -->
						</td>
					</tr>
					
					</tbody>
					</table>
			</div>
			<!-- //search -->


			<!-- textarea -->
			<div class="textarea_box mgt2">
				<textarea rows="2" cols="40" name="text"><%=_text%></textarea>
			</div>
			<!-- //textarea -->

			<!-- btn -->
			<div class="board_btn">
				<a href="javascript:form_submit();" class="btn_orange30"><span>분석하기</span></a>
				<a href="javascript:text_clear();" class="btn_gray30"><span>지문삭제</span></a>
			</div>
			<!-- //btn -->

            <input type="hidden" name="qs" value="<%=qs%>" />

<% if (_text != "")
   { %>
            <!-- Result -->
            <!--c_r_top -->
			<div class="tit_section"> 
				<div class="lside">
					<h2>분석결과</h2>
				</div>
				<div class="rside">
					<a href="javascript:excel_download();" class="btn_gray"><span><img src="/images/btn/ico_excel.gif" alt="엑셀" />다운로드</span></a>
				</div>
			</div>
			<!--//c_r_top -->
			
			<!-- Excel -->
			<div id="word_excel">
			
			    <!-- section : 레벨 별 어휘 분포 (중복포함) -->
			    <div class="linesection">
					<!-- board_top -->
					<div class="board_top">
							<div class="lside">
								<h3>레벨 별 어휘 분포 (중복포함)</h3>
							</div>
							<div class="rside" id="excel_replace">
								<p class="txt">* 가이드라인에 벗어나는 경우 분석 값의 글씨가 빨간색으로 표시</p>
							</div>
					</div>
					<!-- //board_top -->
					<!-- board_view -->
					<div class="board_view">
						<table>
						<!--caption>레벨 별 어휘 분포 : (중복 포함)</caption-->

						<colgroup>
						    <col width="128" />
						    <col width="110" />
						    <col width="110" />
						    <col width="113" span="3" />
						    <col width="150" />
					    </colgroup>
						<thead>
						<tr>
							<th rowSpan="2" scope="col" class="first">가이드라인 항목</th>
							<th rowSpan="2" scope="col">지문 길이</th>
							<th rowSpan="2" scope="col">평균 문장 길이</th>
							<th colSpan="3" scope="col" >어휘 분포</th>
							<th rowSpan="2" scope="col">텍스트 난이도 지수</th>
						</tr>
						<tr style="border-top:1px solid #cdcdcd;">
							<th scope="col"><%=wordScope(action.guideLine.disScope1)%></th>
							<th scope="col"><%=wordScope(action.guideLine.disScope2)%></th>
							<th scope="col"><%=wordScope(action.guideLine.disScope3)%></th>
						</tr>

						</thead>
						<tbody>
						<tr>
							<th class="first">텍스트 분석 값</th>
							<td><%=isRange(action.guideLine.len, action.guideLine.stLenMin, action.guideLine.stLenMax, "")%></td>
							<td><%=isRange(action.guideLine.avg, action.guideLine.avgLenMin, action.guideLine.avgLenMax, "")%></td>
							<td><%=isRange(wordScopePercent(action.guideLine.disScope1, action.overloadWord), action.guideLine.disMin1, action.guideLine.disMax1, "%")%></td>
							<td><%=isRange(wordScopePercent(action.guideLine.disScope2, action.overloadWord), action.guideLine.disMin2, action.guideLine.disMax2, "%")%></td>
							<td><%=isRange(wordScopePercent(action.guideLine.disScope3, action.overloadWord), action.guideLine.disMin3, action.guideLine.disMax3, "%")%></td>
							<td><%=isRange(action.guideLine.lv, action.guideLine.stLevelMin, action.guideLine.stLevelMax, "")%></td>
						</tr>
						<tr>
							<th class="first">가이드라인</th>
							<td><%=getRange(action.guideLine.stLenMin, action.guideLine.stLenMax, "")%></td>
							<td><%=getRange(action.guideLine.avgLenMin, action.guideLine.avgLenMax, "")%></td>
							<td><%=getRange(action.guideLine.disMin1, action.guideLine.disMax1, "%")%></td>
							<td><%=getRange(action.guideLine.disMin2, action.guideLine.disMax2, "%")%></td>
							<td><%=getRange(action.guideLine.disMin3, action.guideLine.disMax3, "%")%></td>
							<td><%=getRange(action.guideLine.stLevelMin, action.guideLine.stLevelMax, "")%></td>
						</tr>
						</tbody>
						</table>
					</div>
					<!-- //board_view -->
                </div>
                <!-- //section : 레벨 별 어휘 분포 (중복포함) -->


                <!-- section : 레벨 별 어휘 분포 (중복포함) -->
				<div class="linesection">
				    <!-- board_top -->
				    <div class="board_top">
						<div class="lside">
							<h3>레벨 별 어휘 분포 (중복포함)</h3>
						</div>
				    </div>
				    <!-- //board_top -->
				    <!-- board_view -->
				    <div class="board_view">
					    <table>
					    <!--caption>레벨 별 어휘 분포 : 보기</caption-->
					    <colgroup>
						    <col width="85" span="8" />
					        <col width="89" />
					    </colgroup>
					    <thead>
					    <tr>
						    <th scope="col" class="first"> Level1 </th>
						    <th scope="col"> Level2 </th>
						    <th scope="col"> Level3 </th>
						    <th scope="col"> Level4 </th>
						    <th scope="col"> Level5 </th>
						    <th scope="col"> Level6 </th>
						    <th scope="col"> Level7 </th>
						    <th scope="col"> 기타 </th>
						    <th scope="col"> 합계 </th>
					    </tr>
					    </thead>
					    <tbody>
					    <tr>
						    <td class="first"><%=((Distribution)action.overloadWord[1]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[2]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[3]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[4]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[5]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[6]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[7]).cnt%></td>
						    <td><%=((Distribution)action.overloadWord[8]).cnt%></td>
						    <td class="total"><%=action.overCnt%></td>
					    </tr>
					    <tr>
						    <td class="first"><%=((Distribution)action.overloadWord[1]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[2]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[3]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[4]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[5]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[6]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[7]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[8]).percent%>%</td>
						    <td class="total">100%</td>
					    </tr>
					    <tr>
						    <td class="first" colSpan="3"><%=((Distribution)action.overloadWord[1]).percent + ((Distribution)action.overloadWord[2]).percent + ((Distribution)action.overloadWord[3]).percent%>%</td>
						    <td colSpan="3"><%=((Distribution)action.overloadWord[4]).percent + ((Distribution)action.overloadWord[5]).percent + ((Distribution)action.overloadWord[6]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[7]).percent%>%</td>
						    <td><%=((Distribution)action.overloadWord[8]).percent%>%</td>
						    <td class="total">100%</td>
					    </tr>

					    </tbody>
					    </table>
				    </div>
				    <!-- //board_view -->
				</div>
                <!-- //section : 레벨 별 어휘 분포 (중복포함) -->
                
			    <!-- section : 레벨 별 어휘 분포 (중복제외) -->
				<div class="linesection">
				    <!-- board_top -->
				    <div class="board_top">
					    <div class="lside">
						    <h3>레벨 별 어휘 분포 (중복제외)</h3>
					    </div>
				    </div>
                    <!-- //board_top -->
                    
				    <!-- board_view -->
				    <div class="board_view">
					    <table>
					    <!--caption>레벨 별 어휘 분포 : 보기</caption-->
					    <colgroup>
						    <col width="85" span="8" />
						    <col width="89" />
					    </colgroup>
					    <thead>
					    <tr>
						    <th scope="col" class="first"> Level1 </th>
						    <th scope="col"> Level2 </th>
						    <th scope="col"> Level3 </th>
						    <th scope="col"> Level4 </th>
						    <th scope="col"> Level5 </th>
						    <th scope="col"> Level6 </th>
						    <th scope="col"> Level7 </th>
						    <th scope="col"> 기타 </th>
						    <th scope="col"> 합계 </th>
					    </tr>
					    </thead>
					    <tbody>
					    <tr>
						    <td class="first"><%=((Distribution)action.nonOverLoadWord[1]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[2]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[3]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[4]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[5]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[6]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[7]).cnt%></td>
						    <td><%=((Distribution)action.nonOverLoadWord[8]).cnt%></td>
						    <td class="total"><%=action.nonOverCnt%></td>
					    </tr>
					    <tr>
						    <td class="first"><%=((Distribution)action.nonOverLoadWord[1]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[2]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[3]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[4]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[5]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[6]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[7]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[8]).percent%>%</td>
						    <td class="total">100%</td>
					    </tr>
					    <tr>
						    <td class="first"  colSpan="3"><%=((Distribution)action.nonOverLoadWord[1]).percent + ((Distribution)action.nonOverLoadWord[2]).percent + ((Distribution)action.nonOverLoadWord[3]).percent%>%</td>
						    <td colSpan="3"><%=((Distribution)action.nonOverLoadWord[4]).percent + ((Distribution)action.nonOverLoadWord[5]).percent + ((Distribution)action.nonOverLoadWord[6]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[7]).percent%>%</td>
						    <td><%=((Distribution)action.nonOverLoadWord[8]).percent%>%</td>
						    <td class="total">100%</td>
					    </tr>
					    </tbody>
					    </table>
				    </div>
				    <!-- //board_view -->
				</div>
			    <!-- //section : 레벨 별 어휘 분포 (중복제외) -->
            </div>
            <!-- //Excel -->
            
		    <!-- section : 레벨 별 단어 상세보기 -->                                                                                                          
			<div class="linesection">
			    <!-- board_top -->
				<div class="board_top">
					<div class="lside">
						<h3>레벨 별 단어 상세보기</h3>
					</div>
					<div class="rside">
						<select name="level1" id="sortSelect" class="select" onchange="sort();">
                            <option value="lv">레벨</option>
                            <option value="fe">빈도</option>
                            <option value="al">알파벳</option>
                        </select>
					</div>
				</div>
				<!-- //board_top -->
			    <!-- board_view -->
				<div class="board_view" id="word_excel2">
					<table>
					<!--caption>레벨 별 단어 : 보기</caption-->
					<colgroup>
						<col width="*" />
						<col width="162" />
						<col width="162" />
						<col width="162" />
						<col width="162" />
					</colgroup>
					<thead>
					<tr>
						<th scope="col" class="first">Level </th>
						<th scope="col">Head Word </th>
						<th scope="col">Frequency </th>
						<th scope="col">Variation </th>
						<th scope="col">Frequency </th>
					</tr>
					</thead>
					<tbody id="lv">
					<%for (int i = 0; i < action.levelSortList.Count; i++)
    {
        CWord word = (CWord)action.levelSortList[i];
                    %>
                    
					<tr>
						<th scope="row" class="first"><%= word.level < 8 ? "Level " + word.level : "기타"%></th>
						<td><%=word.headWord%></td>
						<td><%=word.frequence%></td>
						<%
ArrayList wordList = word.wordList;
for (int j = 0; j < wordList.Count; j++)
{
CWord vWord = (CWord)wordList[j];
if (j > 0)
{
						    %>
						    </tr>
						    <tr>
							    <th scope="row" class="first">&nbsp;</th>
						        <td>&nbsp;</td>
						        <td>&nbsp;</td>
						    <%} %>
						    
						    
						    <td><%=vWord.viewWord%></td>
						    <td><%=vWord.frequence%></td>
						    <%
if (j > 0)
{
						    %>
						    </tr>
						    <%}
}
                            %>
					</tr>
					<%
} 
                    %>
					</tbody>
					
					<tbody id="fe" style="display:none;">
					<%for (int i = 0; i < action.freqSortList.Count; i++)
    {
        CWord word = (CWord)action.freqSortList[i];
                    %>
                    
					<tr>
						<th scope="row" class="first"><%= word.level < 8 ? "Level " + word.level : "기타"%></th>
						<td><%=word.headWord%></td>
						<td><%=word.frequence%></td>
						<%
ArrayList wordList = word.wordList;
for (int j = 0; j < wordList.Count; j++)
{
CWord vWord = (CWord)wordList[j];
if (j > 0)
{
						    %>
						    </tr>
						    <tr>
							    <th scope="row" class="first">&nbsp;</th>
						        <td>&nbsp;</td>
						        <td>&nbsp;</td>
						    <%} %>
						    
						    
						    <td><%=vWord.viewWord%></td>
						    <td><%=vWord.frequence%></td>
						    <%
if (j > 0)
{
						    %>
						    </tr>
						    <%}
}
                            %>
					</tr>
					<%
} 
                    %>
					</tbody>
					
					<tbody id="al" style="display:none;">
					<%for (int i = 0; i < action.alphaSortList.Count; i++)
    {
        CWord word = (CWord)action.alphaSortList[i];
                    %>
                    
					<tr>
						<th scope="row" class="first"><%= word.level < 8 ? "Level " + word.level : "기타"%></th>
						<td><%=word.headWord%></td>
						<td><%=word.frequence%></td>
						<%
ArrayList wordList = word.wordList;
for (int j = 0; j < wordList.Count; j++)
{
CWord vWord = (CWord)wordList[j];
if (j > 0)
{
						    %>
						    </tr>
						    <tr>
							    <th scope="row" class="first">&nbsp;</th>
						        <td>&nbsp;</td>
						        <td>&nbsp;</td>
						    <%} %>
						    
						    
						    <td><%=vWord.viewWord%></td>
						    <td><%=vWord.frequence%></td>
						    <%
if (j > 0)
{
						    %>
						    </tr>
						    <%}
}
                            %>
					</tr>
					<%
} 
                    %>
					</tbody>
					</table>
				</div>
				<!-- //board_view -->
			</div>
			<!-- //section : 레벨 별 단어 상세보기 -->
			
		    <br /><br />
<%} %>
		</div>
		<!-- //contents -->
    </div>
</form>
</body>
</html>
